package org.etlt.job;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class JobMonitor {
    protected Log log = LogFactory.getLog(getClass());

    private JobContext context;

    private int intervalInSeconds = 60;

    public JobMonitor(JobContext context) {
        this.context = context;
    }

    public void start() {
        Thread thread =
                new Thread(() -> {
                    for (; ; ) {
                        try {
                            Thread.sleep(this.intervalInSeconds * 1000);
                        } catch (InterruptedException e) {
                            log.warn("interrupted exception caught.", e );
                        }
                        log.info("[JOB MONITOR]" + context.getUnfinishedLoaders().size() + " loader(s) executing...");
                        log.info("[JOB MONITOR]" + context.getUnfinishedLoaders());
                    }
                }, "JOB-MONITOR");
        thread.setDaemon(true);
        thread.start();
    }
}
